package com.qc.book.util;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class CharEncodinFilter implements Filter {

	public void destroy() {
		// System.out.println("销毁数据.....");
	}

	/*
	 * 保安
	 * 
	 * Filter(过滤器)（Servlet 执行前和执行后进行过滤）
	 */
	
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

		request.setCharacterEncoding("utf-8");

		// 将请求转发给下一个过滤器或者Servlet
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=utf-8");
		
		chain.doFilter(request, response);
	}
	
	public void init(FilterConfig filterConfig) throws ServletException {
		// System.out.println("初始化数据......");
	}

}
